﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShevaEngine.Core.Foundation
{
    /// <summary>
    /// Notification list.
    /// </summary>
    public class NotificationList<T> : List<T>
    {
        /// <summary>Item added event.</summary>
        public event OnNotificationListChangedCallback ItemAdded;
        /// <summary>Item removed event.</summary>
        public event OnNotificationListChangedCallback ItemRemoved;

        /// <summary>
        /// Constructor.
        /// </summary>
        public NotificationList()
            :base()
        {
        }

        /// <summary>
        /// Method adds new item.
        /// </summary>
        /// <param name="item"></param>
        public new void Add(T item)
        {
            base.Add(item);

            if (this.ItemAdded != null)
                this.ItemAdded(this, item);
        }

        /// <summary>
        /// Method removes item.
        /// </summary>
        /// <param name="item"></param>
        public new void Remove(T item)
        {
            if (this.Contains(item))
            {
                base.Remove(item);

                if (this.ItemRemoved != null)
                    this.ItemRemoved(this, item);
            }
        }


        /// <summary>
        /// On notification list changed delegate.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void OnNotificationListChangedCallback(object sender, T e);
    }


    
}
